//
//  NEWMyOrderVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/11/21.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "NEWMyOrderVC.h"
#import "YYNewOrderCell1.h"
#import "YYNewOrderCell2.h"

@interface NEWMyOrderVC ()<SDCycleScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) NSArray * checkArr;
@property (nonatomic ,strong) NSArray * exchangeArr;
@property (nonatomic ,strong) NSArray * giftArr;
@property (nonatomic ,strong) NSArray * rollArr;
@property (nonatomic ,strong) NSArray * schoolArr;
@property (nonatomic ,strong) NSArray * teamArr;
@property (nonatomic ,strong) SDCycleScrollView *adCycleScrollView ;

@end

@implementation NEWMyOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableHeaderView = self.headView;
    self.tableView.tableHeaderView.height =86;
    [self getData];
    self.tableView.mj_header = [MJRefreshStateHeader headerWithRefreshingBlock:^{
        [self getData];
    }];
}

- (void)getData{
    [RequestOperationManager personalOrder_success:^(id result) {
        [self.tableView.mj_header endRefreshing];
        if (DEF_REQ_SUCCESS) {
            self.teamArr = [result[@"data"][@"check"] copy];
             self.exchangeArr = [result[@"data"][@"exchange"] copy];
             self.giftArr = [result[@"data"][@"gift"] copy];
             self.rollArr = [result[@"data"][@"roll"] copy];
             self.schoolArr = [result[@"data"][@"school"] copy];
             self.teamArr = [result[@"data"][@"team"] copy];
            [self reloadData];
        }
        
    } failture:^(NSError *error) {
         [self.tableView.mj_header endRefreshing];
    }];
}

- (void)reloadData{
    NSMutableArray * imgArr = [NSMutableArray arrayWithCapacity:0];
    for (NSDictionary * dic in self.rollArr) {
        [imgArr addObject:[NSString stringWithFormat:@"%@%@",DEF_INTERFACE_WEBVIEWSERVICE,dic[@"image"]]];
    }
    self.adCycleScrollView.imageURLStringsGroup = imgArr;
    if (self.exchangeArr.count+self.teamArr.count+self.schoolArr.count+self.giftArr.count+self.checkArr.count>0) {
         [self.tableView reloadData];
    }else{
        self.baseLabel.text = @"暂无内容";
        self.baseImageView.hidden = NO;
    }
   
}


-(SDCycleScrollView *)adCycleScrollView{
    if (!_adCycleScrollView) {
        _adCycleScrollView =  [SDCycleScrollView cycleScrollViewWithFrame:self.headView.bounds delegate:self placeholderImage:[UIImage new]];
        _adCycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _adCycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _adCycleScrollView.currentPageDotColor = [UIColor colorWithHexString:@"08c5ed"];
        _adCycleScrollView.pageDotColor = [UIColor colorWithHexString:@"bdbdbd"];
        _adCycleScrollView.pageControlDotSize = CGSizeMake(4, 4);  // pageControl小点的大小
        _adCycleScrollView.contentMode = UIViewContentModeScaleAspectFill;
        [self.headView addSubview:_adCycleScrollView];
        [_adCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(0);
        }];
    }
    return _adCycleScrollView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.exchangeArr.count;
    }
    if (section == 1) {
         return self.giftArr.count;
    }
    if (section == 2) {
         return self.schoolArr.count;
    }
    if (section == 3) {
         return self.teamArr.count;
    }
    if (section == 4) {
         return self.checkArr.count;
    }
 
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        YYNewOrderCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"YYNewOrderCell2"];
        NSDictionary * itme = self.exchangeArr[indexPath.row];
        cell.icon.image = DEF_IMAGENAME(@"MyOrder_ stores");
         cell.lbName.text = itme[@"seller_name"];
        cell.lbType.text = @"[门店]";
        cell.lbContent.text = [NSString stringWithFormat:@"服务内容：%@",itme[@"product"]];
        cell.lbTag.text = @"已购买";
        return cell;
    }
    if (indexPath.section == 1) {
        YYNewOrderCell1 * cell = [tableView dequeueReusableCellWithIdentifier:@"YYNewOrderCell1"];
         NSDictionary * itme = self.giftArr[indexPath.row];
         cell.icon.image = DEF_IMAGENAME(@"MyOrder_Gift bag");
        cell.lbName.text = itme[@"name"];
        cell.lbType.text = @"[礼包]";
        cell.lbPrice.text = itme[@"price"];
        cell.lbCard.hidden = YES;
         cell.lbTag.text = @"已购买";
        return cell;
    }
    if (indexPath.section == 2) {
        YYNewOrderCell1 * cell = [tableView dequeueReusableCellWithIdentifier:@"YYNewOrderCell1"];
         NSDictionary * itme = self.schoolArr[indexPath.row];
         cell.icon.image = DEF_IMAGENAME(@"MyOrder_stuCar");
         cell.lbName.text = itme[@"school_name"];
        cell.lbType.text = @"[学车]";
        cell.lbPrice.text = itme[@"money"];
        cell.lbCard.hidden = NO;
        cell.lbCard.text = itme[@"card_type"];
         cell.lbTag.text = @"已报名";
        return cell;
    }
    if (indexPath.section == 3) {
        YYNewOrderCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"YYNewOrderCell2"];
         NSDictionary * itme = self.teamArr[indexPath.row];
         cell.icon.image = DEF_IMAGENAME(@"MyOrder_Check the car");
         cell.lbName.text = itme[@"name"];
        cell.lbType.text = @"[检车]";
        cell.lbContent.text = [NSString stringWithFormat:@"检车数量:%@辆",itme[@"number"]];
         cell.lbTag.text = @"已预约";
        return cell;
    }
    if (indexPath.section == 4) {
        YYNewOrderCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"YYNewOrderCell2"];
         NSDictionary * itme = self.checkArr[indexPath.row];
         cell.icon.image = DEF_IMAGENAME(@"MyOrder_Check the car");
         cell.lbName.text = itme[@"name"];
        cell.lbType.text = @"[检车]";
        cell.lbContent.text = [NSString stringWithFormat:@"预约时间:%@",itme[@"add_time"]];
         cell.lbTag.text = @"已预约";
        return cell;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ((indexPath.section == 1||indexPath.section == 2)) {
        return 94;
    }else{
        return 80;
    }
}
@end
